+function () {
    var keys = {
        ESC: 27,
        TAB: 9,
        RETURN: 13,
        LEFT: 37,
        UP: 38,
        RIGHT: 39,
        DOWN: 40
    };
    /*
     $searchData: 搜索结果(目的地全称+逗号+目的地所属行政区)
     $searchName: 目的地全称
     $parentName: 目的地所属行政区
     $searchCount: 酒店数量
     $searchType: 目的地类型
     */
    var destinationModel = "<li><a href='javascript:;' data-place=\"$searchData\" data-id=\"$searchID\"><span class=\"place-name\">$searchName</span></a></li>";
    var $elements, $activedElement, timeoutId;
    var querySelecter = {
        completeBox: ".complete-wrap",
        destinationBox: ".destinationBox",
        errorTipsBox: ".des_error_tips",
        destInput: ".input-city"
    };

    function Factory() {
        $elements = this;
        return new SearchComplete();
    }

    //多次请求流规避
    function timeoutFn() {
        var fn = new SearchComplete("none");
        fn.requestData();
    }

    function SearchComplete(option) {
        if (option)
            return;
        this.initialize();
        return $elements;
    }

    SearchComplete.prototype = {
        initialize: function () {
            var that = this;
            that.createContainer();
            that.bindEvent();
        },
        createContainer: function () {
            var html = [];
            html.push("<div class=\"complete-wrap destinationBox\" style=\"display:none\"></div>");
            html.push("<div class=\"des_error_tips\" style=\"display:none;\"><span>没有找到含“</span><span style=\"color:#e38;font-weight:bold\" class=\"word\"></span><span>”的城市</span></div>");
            if ($(querySelecter.destinationBox).size() <= 0)
                $("body").append(html.join(''));
        },
        bindEvent: function () {
            var that = this;
            that.bindKeyupEvent();
            that.bindFoucsEvent();
            that.bindBlurEvent();
            that.bindMouseEvent();
        },
        bindKeyupEvent: function () {
            var that = this;
            //$elements.unbind("keydown");
            $elements.bind("keydown", function (e) { //取消form的自动submit事件
                switch (e.which) {
                    case keys.RETURN:
                        e = e || window.event;
                        if (!e.preventDefault())
                            e.returnValue = false;
                        break;
                }

                $(".errTips").hide();
                $(".input-city").removeClass('ft-city-error');
            });
            //$elements.unbind("keyup");
            $elements.bind("keyup", function (e) {
                switch (e.which) {
                    case keys.UP:
                        that.moveUp();
                        break;
                    case keys.DOWN:
                        that.moveDown();
                        break;
                    case keys.ESC:
                        $(querySelecter.completeBox).html("").hide();
                        break;
                    case keys.RETURN:
                        if ($(querySelecter.completeBox).is(":visible")) {
                            that.select(e);
                        }
                        $(this).removeClass("ft-city-error");
                        var $thisSearchPart = $(this).parents(".JS_search");
                        var $thisDest = $thisSearchPart.find(".JS_select_dest");
                        if ($(this).hasClass("JS_select_depa") && ( $thisDest.val() == "" || $thisDest.val() == $thisDest.attr("placeholder"))) {
                            $(querySelecter.completeBox).html("").hide();
                            $thisDest.focus();
                        }
                        break;
                    default:
                        clearTimeout(timeoutId);
                        timeoutId = setTimeout(timeoutFn, 300);
                        break;
                }
            });

        },
        bindFoucsEvent: function () {
            var that = this;
            $elements.bind("focus", function (e) {
                var target = e.target;
                $activedElement = $(target);

                //设置自动完成列表层定位
                var UlPosition = {
                    left: $activedElement.offset().left,
                    top: $activedElement.offset().top + $activedElement.outerHeight() - 1
                };
                var UlWidth = $activedElement.outerWidth();
                var $targetBox = that.getActivedBox();
                $targetBox.css({
                    left: UlPosition.left,
                    top: UlPosition.top,
                    width: $activedElement.outerWidth(true) - 2
                });
                if (target.value != "") {
                    return;
                }
                if ($activedElement.val() !== "")
                    that.requestData();
                $("input:text[active]").removeAttr("active");
                $(target).attr("active", "actived");
            });

            //$elements.unbind("click");
            $elements.bind("click", function (e) {
                that.cancelBubble(e);
            });
        },
        bindBlurEvent: function () {
        },
        bindMouseEvent: function () {
            var that = this;
            $(querySelecter.completeBox).bind("click", function (e) {
                e.stopPropagation();
                var target = e.target;
                var $keyword = $(".js_keyword:visible");
                switch (target.tagName.toLowerCase()) {
                    case "a":
                        $activedElement.val($(target).attr("data-place"));
                        $keyword.attr("data-id", $(target).attr("data-id"));
                        break;
                    case "b":
                        $activedElement.val($(target).parent().parent().attr("data-place"));
                        $keyword.attr("data-id", $(target).parent().parent().attr("data-id"));
                        break;
                    case "span":
                        $activedElement.val($(target).parent().attr("data-place"));
                        $keyword.attr("data-id", $(target).parent().attr("data-id"));
                        $activedElement.removeClass("ft-city-error");
                        var $thisSearchPart = $activedElement.parents(".JS_search");
                        var $thisDest = $thisSearchPart.find(".JS_select_dest");
                        if ($activedElement.hasClass("JS_select_depa") && ( $thisDest.val() == "" || $thisDest.val() == $thisDest.attr("placeholder"))) {
                            $(querySelecter.completeBox).html("").hide();
                            $thisDest.focus();
                        }
                        break;
                    case "li":
                        $activedElement.val($(target).find("a").attr("data-place"));
                        $keyword.attr("data-id", $(target).find("a").attr("data-id"));
                        break;
                }
                that.getActivedBox().html("").hide();

            });
            $(querySelecter.errorTipsBox).find("i").bind("mousedown", function () {
                $(this).parent().hide();
            });
        },
        moveDown: function () {
            var that = this;
            if (!that.hasValue()) {
                return;
            }
            var $libox = that.getActivedBox();
            var $activeLi = $libox.find("li.active");
            if ($activeLi.size() > 0) {
                if ($activeLi.next().size() > 0) {
                    $activeLi.removeClass("active").next().addClass("active");
                } else if ($activeLi.prev().size() > 0) {
                    $activeLi.removeClass("active").siblings(":first").addClass("active")
                }
            } else {
                $libox.find("li:first").addClass("active")
            }
            var $actived = $libox.find("li.active");
            $activedElement.val($actived.find("a").attr("data-place"));
        },
        moveUp: function () {
            var that = this;
            if (!that.hasValue()) {
                return;
            }
            var $libox = that.getActivedBox();
            var $activeLi = $libox.find("li.active");
            if ($activeLi.size() > 0) {
                if ($activeLi.prev().size() > 0) {
                    $activeLi.removeClass("active").prev().addClass("active");
                } else if ($activeLi.next().size() > 0) {
                    $activeLi.removeClass("active").siblings(":last").addClass("active")
                }
            } else {
                $libox.find("li:last").addClass("active")
            }
            var $actived = $libox.find("li.active");
            $activedElement.val($actived.find("a").attr("data-place"));

        },
        select: function (e) {
            var $activedLink = this.getActivedBox().find("li.active>a");
            if ($activedLink.size() > 0) {
                $activedElement.val($activedLink.attr("data-place"));
                $(".js_keyword:visible").attr("data-id", $activedLink.attr("data-id"));
            }
            $(querySelecter.completeBox).html("").hide();
        },
        hasValue: function () {
            if ($.trim($activedElement.val()) === "")
                return false;
            else
                return true;
        },
        getActivedBox: function () {
            return $(querySelecter.destinationBox);
        },
        cancelBubble: function (e) {
            e = e || window.event;
            if (!e.stopPropagation())
                e.cancelBubble = true;
        },
        requestData: function () { //开始请求数据
            var that = this;
            if (!that.hasValue()) {
                that.getActivedBox().hide();
                return;
            }
            if ($activedElement.hasClass("input-city")) {
                $(querySelecter.errorTipsBox).hide();
            }
            var keyword = $activedElement.val();
            // var dataStr = ("type=DEST&keyword=" + keyword.split(",")[0]);
            // var ajaxurl = "http://s.lvmama.com/autocomplete/autoCompleteHotel.do";
            var qq = [];
            $.each(allCities, function (index, items) {
                var finalModel = destinationModel.replace("$searchData", items.split("|")[0]);
                finalModel = finalModel.replace("$searchID", items.split("|")[3]);
                finalModel = finalModel.replace("$searchName", items.split("|")[0]);
                var goCityV = $activedElement.val().toLocaleLowerCase().replace(/ /g, "");

                if (items.split("|")[0].indexOf(goCityV) != -1 || items.split("|")[1].indexOf(goCityV) != -1 || items.split("|")[2].indexOf(goCityV) != -1 || items.split("|")[3].toLocaleLowerCase().indexOf(goCityV) != -1) {
                    qq.push(items);
                }
            });
            that.dataBind(qq);
        },
        dataBind: function (data) { //数据可视化
            var that = this;
            if (!(typeof data === "object"))
                return;
            var html = "";
            //拼接补全位
            if (data) {
                if (that.getActivedBox().hasClass("destinationBox")) { //目的地补全
                    var canton = [];
                    $.each(data, function (index, items) {
                        var finalModel = destinationModel.replace("$searchData", items.split("|")[0]);
                        finalModel = finalModel.replace("$searchID", items.split("|")[3]);
                        finalModel = finalModel.replace("$searchName", items.split("|")[0]);
                        if (canton.length >= 10) {

                        } else {
                            canton.push(finalModel);
                        }
                    });
                    if (canton.length == 0)
                        html = "";
                    else
                        html = "<ul>" + canton.join('') + "</ul>";
                }
            }
            if (html === "") {
                that.getActivedBox().hide();
                if ($activedElement.hasClass("input-city")) {
                    var thisL = $activedElement.offset().left,
                        thisT = $activedElement.offset().top,
                        thisH = $activedElement.outerHeight(true),
                        thisW = $activedElement.outerWidth(true) - 12;
                    $(querySelecter.errorTipsBox).show().css({
                        'left': thisL,
                        'top': thisT + thisH - 1,
                        'width': thisW
                    }).find(".word").text($activedElement.val());
                }
                return;
            }
            that.getActivedBox().show().html(html);

            if ($activedElement.hasClass("input-city")) {
                var $a = that.getActivedBox().find("li:first").addClass("active").find("a");
                $(".js_keyword:visible").attr("data-id", $a.attr("data-id"));
            }
        }
    };

    $.fn.cityComplete = $.cityComplete = Factory;
}();

+function searchInputInit() {
    /*目的地输入框*/
    $(".input-city").bind({
        "focus": function () {
            var $this = $(this);
            var $thisSearchPart = $(this).parents(".JS_search");
            $(".input-city").removeClass("JS_city_active");
            $this.addClass("JS_city_active");
            // if($(".invalid-city-error").is(":visible")){
            $(".invalid-city-error,.same-city-error").hide();
            // }

            var thisL = $this.offset().left,
                thisT = $this.offset().top,
                thisH = $this.outerHeight(true);
            $(".JS_mt_hot").click();
            if (!$(".complete-wrap").is(':visible') && !$(".des_error_tips").is(':visible')) {
                showHistory($this);
                $('.city_mdd').show().css({
                    'left': thisL,
                    'top': thisT + thisH - 1
                });
            }
        },
        "blur": function () {
            var $this = $(this);
            var $thisSearchPart = $(this).parents(".JS_search");
            var $thisDest = $thisSearchPart.find(".JS_select_dest");
            $(".des_error_tips").hide();
            if ($this.val() != "" && $this.val() != $this.attr("placeholder")) {
                $(this).removeClass("ft-city-error");
            }
            // if($(".same-city-error").is(":visible")){
            $(".same-city-error").hide();
            // $thisDest.removeClass("ft-city-error");
            // }

        },
        "keyup": function () {
            var $this = $(this);
            if ($.trim($this.val()) == '') {
                var thisL = $this.offset().left,
                    thisT = $this.offset().top,
                    thisH = $this.outerHeight(true);
                showHistory($this);
                $('.city_mdd').show().css({
                    'left': thisL,
                    'top': thisT + thisH
                });
            } else {
                $('.city_mdd').hide();
            }
        },
        "click": function (e) {
            e.stopPropagation();
            $(this).select();
            $('.ui-calendar:not(".lp-calendar")').remove();
        }
    });

    function showHistory($element) {
        if ($(".mdd_history").length) {
            var index = $element.hasClass('JS_select_depa') ? 0 : 1;
            $('.mdd_his_content').hide().eq(index).show();
        }
    }
}();

$(function () {

    if (!("placeholder" in document.createElement("input"))) {

        var $document = $(document);

        $("input[placeholder], textarea[placeholder]").each(function () {
            var $this = $(this),
                text = $this.attr("placeholder");
            if ($this.val() === "") {
                $this.val(text).addClass("placeholder");
            }

        });

        $document.on("focus", "input[placeholder],textarea[placeholder]", function () {

            var $this = $(this),
                text = $this.attr("placeholder");
            if ($this.val() === text) {
                $this.val("").removeClass("placeholder");
            }
        });

        $document.on("blur", "input[placeholder],textarea[placeholder]", function () {
            var $this = $(this),
                text = $this.attr("placeholder");
            if ($this.val() === "") {
                $this.val(text).addClass("placeholder");
            }
        });

        $document.on("submit", "form", function () {
            var $this = $(this);
            var $input = $this.find("input[placeholder],textarea[placeholder]");
            $input.each(function (index, ele) {
                var $ele = $(ele);
                if ($ele.val() === $ele.attr("placeholder")) {
                    $(ele).val("");
                }
            });
        });

    }

});

$(function () {
    $(document).bind("click", function (event) {
        removeAllPopUp();
    });
    // 自动补全hover
    $(document).on("mouseenter", ".complete-wrap a", function () {
        var $thisLi = $(this).parent();
        $thisLi.addClass('active').siblings().removeClass('active');
    });

    $(".input-city").cityComplete();

    // 日历功能
    $(".ft-calendar-info").on("click", function (e) {
        e.stopPropagation();
        var $input = $(this).siblings("input.input-calendar");
        $input.focus();
        $input.click();
    });

    $(".input-calendar").click(function () {
        // 清除其他弹框
        removeAllPopUp();
        $('.ui-calendar:not(".lp-calendar")').remove();
    });

    var isFlightCascading = !$(".ft-type a:first").hasClass('active');

    var flightCalendar = lv.calendar({
        autoRender: false,
        trigger: ".input-calendar",
        triggerEvent: "click",
        bimonthly: true,
        template: "small",
        cascading: true,
        cascadingOffset: 3,
        // cascadingMax: 10,
        showNumberOfDays: true,
        cascadingNextAuto: isFlightCascading,
        selectDateCallback: flightSelectDateCallback,
        cascadingCallback: flightCascadingCallback
    });

    function flightSelectDateCallback(cal) {
        // 是否为第二个日历
        if (cal.$trigger[0] === $(cal.options.trigger).eq(1)[0] && $(".ft-input-group-disable").length) {
            $(".ft-type a:last").click();
        } else if (!cal.options.cascadingNextAuto) {
            setTimeout(function () {
                $(".ft-return-day-group .ft-calendar-info span").html("星期" + dayArray[getDaysAfter(0, $(".JS_calendar_back").val()).day]);
            }, 10);
        }
        setDayOfWeek(cal);
    }

    function flightCascadingCallback(cal, $flightEndDate) {
        var $flightEndDayInfo = $flightEndDate.siblings('.ft-calendar-info').find("span");
        $flightEndDayInfo.html(cal.getDayOfWeek());
    }

    function setDayOfWeek(cal) {
        var $thisInput = cal.$trigger;
        var $dayOfWeek = $thisInput.siblings('.ft-calendar-info').find("span");
        $dayOfWeek.html(cal.getDayOfWeek());
    }

    // 城市选择
    $(".city_mdd").bind({
        "click": function (e) {
            e.stopPropagation();
            var target = e.target;
            switch (target.tagName.toLowerCase()) {
                case "a":
                    var city = $(target).text();
                    var $thisCity = $(".JS_city_active");
                    $thisCity.removeClass("ft-city-error");
                    setCity($thisCity, city);
                    $(this).hide();

                    var $thisSearchPart = $thisCity.parents(".JS_search");
                    var $thisDest = $thisSearchPart.find(".JS_select_dest");
                    // 出发地填充后，若目的地无值点开目的地选择框
                    if ($thisCity.hasClass("JS_select_depa") && ( $thisDest.val() == "" || $thisDest.val() == $thisDest.attr("placeholder"))) {
                        $thisDest.focus();
                    }
                    break;
                case "li":
                    var $this = $(target);
                    var $thisParent = $this.parent();
                    var $history = $thisParent.siblings('.mdd_history');
                    $this.addClass('active').siblings().removeClass('active');
                    $thisParent.siblings('.mdd_list').find("li:eq(" + $this.index() + ")").show().siblings().hide();
                    if ($this.index() == 0) {
                        $history.show();
                    } else {
                        $history.hide();
                    }
                    break;
                case "span":
                    $(this).hide();
                    break;
            }
        },
        "mousedown": function (e) {
            e.stopPropagation();
        }
    });

    function setCity($element, city) {
        $element.removeClass("ft-city-error").removeClass("placeholder");
        $element.val(city);
    }

    function removeAllPopUp() {
        $(".city_mdd, .des_error_tips, .complete-wrap, .invalid-city-error, .same-city-error").hide();
        // $(".ui-calendar").remove();
    }

    //获取默认日期的星期值
    var dayArray = ["天", "一", "二", "三", "四", "五", "六"];
    var $tomorrow = $(".tomorrow");
    var $dayAfter3 = $(".dayAfter3")

    var tomorrowJson = getDaysAfter(0, $(".JS_calendar_depa").val());
    $tomorrow.html("星期" + dayArray[tomorrowJson.day]);

    if ($(".JS_calendar_back").val() != "YYYY-MM-DD") {
        var dayAfter3Json = getDaysAfter(0, $(".JS_calendar_back").val());
        $dayAfter3.html("星期" + dayArray[dayAfter3Json.day]);
    }

    // 单程、往返切换
    $(".ft-type a").on("click", function (e) {
        e.stopPropagation();
        var $this = $(this);
        if (!$this.hasClass("active")) {
            var $returnDayGroup = $(".ft-return-day-group");
            var $backCalendar = $(".JS_calendar_back");
            var $dayAfter3 = $(".dayAfter3");
            $(".input-flight-type").val($this.data("type"));
            $this.addClass("active").siblings().removeClass("active");
            $returnDayGroup.toggleClass("ft-input-group-disable");
            // if($returnDayGroup.hasClass("ft-input-group-disable")){
            //     $returnDayGroup.removeClass("ft-input-group-disable");
            //     if($backCalendar.val()=="YYYY-MM-DD") {
            //         var day = $(".JS_calendar_depa").val();
            //         var dayJson = getDaysAfter(3, day);
            //         $backCalendar.val(dayJson.dateString);
            //         $dayAfter3.html("星期" + dayArray[dayJson.day]);
            //     }
            // } else {
            //     $backCalendar.val("YYYY-MM-DD");
            //     $dayAfter3.html("");
            //     $returnDayGroup.addClass("ft-input-group-disable");
            // }
        }
        // 配合日历
        if ($(".ft-input-group-disable").length) {
            flightCalendar.options.cascadingNextAuto = false;
        } else {
            flightCalendar.options.cascadingNextAuto = true;
        }
    });

    $(".ft-input-cities a, .change-city").on("click", function (e) {
        e.stopPropagation();
        $(".city_mdd, .invalid-city-error").hide();
        var $this = $(this);
        var $thisSearchPart = $this.parents('.JS_search');
        var $depa = $thisSearchPart.find(".JS_select_depa");
        var $dest = $thisSearchPart.find(".JS_select_dest");

        var temp = $dest.val();
        if ($depa.val() == $depa.attr("placeholder")) {
            $dest.val("");
        } else {
            $dest.val($depa.val());
        }
        if (temp == $dest.attr("placeholder")) {
            $depa.val("");
        } else {
            $depa.val(temp);
        }
        if (!$(".same-city-error").is(":visible")) {
            checkCityInputs($thisSearchPart);
        }
    });

    function checkCityInputs($element) {
        var $cityInputs = $element.find(".input-city");
        $cityInputs.removeClass("ft-city-error");
        for (var i = 0; i < $cityInputs.length; i++) {
            var $thisInput = $cityInputs.eq(i);
            if ($thisInput.val() === "" || $thisInput.val() === $thisInput.attr("placeholder")) {
                $thisInput.addClass("ft-city-error");
                if (!$(".city_mdd").is(":visible")) {
                    $thisInput.focus();
                }
            }
        }
    }

    /**
     * getDaysAfter 加天数
     * @param {number} atfer
     * @param {string} now 格式:"YYYY-MM-DD"
     */
    function getDaysAfter(atfer, now) {
        var nowDay;
        if (now) {
            var dayArray = now.split("-");
            nowDay = new Date(parseInt(dayArray[0], 10), parseInt(dayArray[1], 10) - 1, parseInt(dayArray[2], 10));
        } else {
            nowDay = new Date();
        }
        var threeDayAfter = new Date(nowDay.getTime() + atfer * 24 * 60 * 60 * 1000);
        var y = threeDayAfter.getFullYear();
        var m = threeDayAfter.getMonth() + 1;
        var d = threeDayAfter.getDate();
        var day = threeDayAfter.getDay();
        var dateString = y + "-" + (m >= 10 ? m : "0" + m) + "-" + (d >= 10 ? d : "0" + d);
        return {
            day: day,
            dateString: dateString
        };
    }

});

function validateFtInput($element) {
    var $thisSearchPart = $element.parents('.JS_search');
    var $cityInput = $thisSearchPart.find(".input-city");
    var $cityMdd = $(".city_mdd");
    $(".des_error_tips, .complete-wrap").hide();
    $cityMdd.hide();
    $cityInput.removeClass("ft-city-error");
    for (var i = 0; i < $cityInput.length; i++) {
        var $thisCityInput = $cityInput.eq(i);
        if ($thisCityInput.val() === "" || $thisCityInput.val() === $thisCityInput.attr("placeholder")) {
            $thisCityInput.addClass("ft-city-error");
            if (!$cityMdd.is(":visible")) {
                $thisCityInput.focus();
            }
            return false;
        }
    }

    var $depa = $thisSearchPart.find(".JS_select_depa");
    var $dest = $thisSearchPart.find(".JS_select_dest");

    var depa = $.trim($depa.val());
    var dest = $.trim($dest.val());

    if (dest == depa) {
        // $dest.addClass("ft-city-error");
        showSameCity($dest);
        return false;
    }

    if (!isValidCity(depa)) {
        showErrorCity($depa);
        return false;
    }

    if (!isValidCity(dest)) {
        showErrorCity($dest);
        return false;
    }

    return true;

    function showSameCity($element) {
        $element.addClass('ft-city-error');
        $(".same-city-error").css(getPositon($element)).show();
    }

    function showErrorCity($element) {
        $element.addClass('ft-city-error');
        $(".invalid-city-error").css(getPositon($element)).show();
    }

    function getPositon($element) {
        return {
            left: $element.offset().left,
            top: $element.offset().top + $element.outerHeight() + 8
        }
    }
}

function isValidCity(city) {
    for (var i = 0; i < allCities.length; i++) {
        if (allCities[i].split("|")[0] == city) {
            return true;
        }
    }
    return false;
}


+function () {
    $.fn.ckSlide = function (opts) {
        opts = $.extend({}, $.fn.ckSlide.opts, opts);
        this.each(function () {
            var slidewrap = $(this).find('.ck-slide-wrapper');
            var slide = slidewrap.find('li');
            var count = slide.length;
            var that = this;
            var index = 0;
            var time = null;
            $(this).data('opts', opts);

            if (slidewrap.children('li').length > 1) {
                var dotsDom = '';
                for (var i = 0; i < slidewrap.children('li').length; i++) {
                    if (i < 1) {
                        dotsDom += '<li class="current"></li>';
                    } else {
                        dotsDom += '<li></li>';
                    }
                }
                $('.dot-wrap').append(dotsDom);
            }

            $(this).find('.ck-next').on('click', function () {
                if (opts['isAnimate'] == true) {
                    return;
                }

                var old = index;
                if (index >= count - 1) {
                    index = 0;
                } else {
                    index++;
                }
                change.call(that, index, old);
            });
            $(this).find('.ck-prev').on('click', function () {
                if (opts['isAnimate'] == true) {
                    return;
                }

                var old = index;
                if (index <= 0) {
                    index = count - 1;
                } else {
                    index--;
                }
                change.call(that, index, old);
            });
            $(this).find('.dot-wrap li').each(function (cindex) {
                $(this).on('mouseenter.slidebox', function () {
                    change.call(that, cindex, index);
                    index = cindex;
                });
            });

            $(this).on('mouseover', function () {
                if (opts.autoPlay) {
                    clearInterval(time);
                }
                // $(this).find('.ctrl-slide').css({opacity: 0.6});
            });
            $(this).on('mouseleave', function () {
                if (opts.autoPlay) {
                    startAtuoPlay();
                }
                // $(this).find('.ctrl-slide').css({opacity: 0.15});
            });
            startAtuoPlay();
            function startAtuoPlay() {
                if (opts.autoPlay) {
                    time = setInterval(function () {
                        var old = index;
                        if (index >= count - 1) {
                            index = 0;
                        } else {
                            index++;
                        }
                        change.call(that, index, old);
                    }, 4000);
                }
            }

            var box = $(this).find('.ck-slidebox');
            box.css({
                'margin-left': -(box.width() / 2)
            });
            switch (opts.dir) {
                case "x":
                    opts['width'] = $(this).width();
                    slidewrap.css({
                        'width': count * opts['width']
                    });
                    slide.css({
                        'float': 'left',
                        'position': 'relative'
                    });
                    slidewrap.wrap('<div class="ck-slide-dir"></div>');
                    slide.show();
                    break;
            }
        });
    };
    function change(show, hide) {
        var opts = $(this).data('opts');
        if (opts.dir == 'x') {
            var x = show * opts['width'];
            $(this).find('.ck-slide-wrapper').stop().animate({'margin-left': -x}, function () {
                opts['isAnimate'] = false;
            });
            opts['isAnimate'] = true
        } else {
            $(this).find('.ck-slide-wrapper li').eq(hide).stop().animate({opacity: 0});
            $(this).find('.ck-slide-wrapper li').eq(show).show().css({opacity: 0}).stop().animate({opacity: 1});
        }

        $(this).find('.dot-wrap li').removeClass('current');
        $(this).find('.dot-wrap li').eq(show).addClass('current');
    }

    $.fn.ckSlide.opts = {
        autoPlay: false,
        dir: null,
        isAnimate: false
    };
}();


$(function () {
    $('.ck-slide').ckSlide({
        autoPlay: true
    });
});
